package com.application.outdoor.adapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.application.Activity.R;
import com.application.outdoor.pojo.LogThaoTacPOJO;

public class LogThaoTacAdapter extends BaseAdapter{
	private ArrayList<LogThaoTacPOJO> data;
	private Context context;
	private LayoutInflater inflater;
	public LogThaoTacAdapter(Context context, ArrayList<LogThaoTacPOJO> data){
		this.context=context;
		this.data=data;
		this.inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		return data.size();
	}
	@Override
	public LogThaoTacPOJO getItem(int position) {
		return data.get(position);
	}
	@Override
	public long getItemId(int position) {
		return data.get(position).getId();
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view=convertView;
		if(view==null){
			view=inflater.inflate(R.layout.od_row_log_thao_tac, null);
			ViewHolder holder=new ViewHolder();
			holder.txtHanhDong=(TextView)view.findViewById(R.id.txtHanhDong);
			holder.txtNguoiDung=(TextView)view.findViewById(R.id.txtNguoiDung);
			holder.txtThoiGian=(TextView)view.findViewById(R.id.txtThoiGian);
			view.setTag(holder);
		}
		
		ViewHolder holder=(ViewHolder)view.getTag();
		holder.txtHanhDong.setText(data.get(position).getHanhDong());
		holder.txtNguoiDung.setText(data.get(position).getNguoiDung());
		holder.txtThoiGian.setText(new SimpleDateFormat("hh:mm:ss dd-MM-yyyy").format(new Date(data.get(position).getThoiGian())));
		
		return view;
	}
	private class ViewHolder{
		TextView txtHanhDong, txtNguoiDung, txtThoiGian;
	}
}

